package com.ys.controller.web.hr;

import java.math.BigDecimal;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.bo.vo.W;
import com.ys.config.MenuId;
import com.ys.config.MyConfig;
import com.ys.entity.hr.TbJobLevel;
import com.ys.service.sys.CommonApiService;

@Controller
@RequestMapping("/web/hr/tbJobLevel")
public class WebTbJobLevelController {
	@Autowired
	private CommonApiService<TbJobLevel> commonApiService;

	/*
	 * 新增
	 */
	@GetMapping("/toAdd")
	public String toAdd(Model model, HttpServletRequest request, HttpServletResponse response) throws Exception{
        TbJobLevel entity = new TbJobLevel();
        entity.setBasicSalary(new BigDecimal(1800))
        	.setStatus(1);
        String aa = commonApiService.toAdd(model, entity, MenuId.TB_JobLevel, null, null);
        
        if ("test".equals(MyConfig.getActive()) || "pro".equals(MyConfig.getActive())) {
            return "hr/tbJobLevel/toAdd";
		} else {
			return aa;
		}
	}

	/*
	 * 编辑
	 */
	@GetMapping("/toEdit")
	public String toEdit(Model model, HttpServletRequest request, HttpServletResponse response,
			Long id) throws Exception{
		if (id == null){
			return W.error(model, "id不能为空");
		}

		if (new TbJobLevel().setId(id).count() == 0){
			return W.error(model, "该信息不存在!");
		}

		String aa = commonApiService.toEdit(model, id, new TbJobLevel(), MenuId.TB_JobLevel, null, null);
        
        if ("test".equals(MyConfig.getActive()) || "pro".equals(MyConfig.getActive())) {
    		return "hr/tbJobLevel/toEdit";
		} else {
			return aa;
		}

	}
}
